package net.ddns.xcyyds.kungfu.procedures;

import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.entity.Entity;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.advancements.AdvancementProgress;
import net.minecraft.advancements.Advancement;

import net.ddns.xcyyds.kungfu.network.KungFuModVariables;

import java.util.Iterator;

public class UseArm2Procedure {
	public static void execute(LevelAccessor world, double x, double y, double z, Entity entity) {
		if (entity == null)
			return;
		if (!(entity.getCapability(KungFuModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new KungFuModVariables.PlayerVariables())).howToUse) {
			entity.getPersistentData().putBoolean("kungFuUse", (false));
			if (entity instanceof ServerPlayer _player) {
				Advancement _adv = _player.server.getAdvancements().getAdvancement(new ResourceLocation("kung_fu:kung_fu_1"));
				AdvancementProgress _ap = _player.getAdvancements().getOrStartProgress(_adv);
				if (!_ap.isDone()) {
					Iterator _iterator = _ap.getRemainingCriteria().iterator();
					while (_iterator.hasNext())
						_player.getAdvancements().award(_adv, (String) _iterator.next());
				}
			}
			FirstProcedure.execute(world, x, y, z, entity);
			NewNBTProcedure.execute(entity);
		}
	}
}
